package com.leetcode.August;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 6. Z 字形变换、
 * 看题解
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-23 09:37
 */
public class LC6Z字形变换 {
    public String convert(String s, int numRows) {
     if (numRows <2) return s;
        List<StringBuilder> rows = new ArrayList<StringBuilder>();
        int i=0,flag = -1;
        for (char c : s.toCharArray()) {
            rows.get(i).append(c);
            if (i==0 || i==numRows-1) flag = -flag;
            i += flag;
        }
        StringBuilder res = new StringBuilder();
        for (StringBuilder row : rows) {
            res.append(row);
        }
        return res.toString();
    }
}
